package com.edfu.core.identitymgt.util;

import com.edfu.core.dyna.util.DynaUtil;
import com.edfu.core.identitymgt.persistence.entity.PermissionEntity;
import com.edfu.core.identitymgt.persistence.entity.RoleEntity;
import com.edfu.core.identitymgt.persistence.entity.UserEnrollmentDataEntity;
import com.edfu.core.identitymgt.persistence.entity.UserEnrollmentEntity;
import com.edfu.core.identitymgt.persistence.entity.UserEntity;
import com.edfu.core.identitymgt.vo.Permission;
import com.edfu.core.identitymgt.vo.Role;
import com.edfu.core.identitymgt.vo.User;
import com.edfu.core.identitymgt.vo.UserEnrollment;

public class IdentityMgtModelConverter {
	public static RoleEntity getRoleEntity(Role from) {
		RoleEntity to = new RoleEntity();
		to.setDescription(from.getDescription());
		to.setName(from.getName());
		to.setDisplayLabel(from.getDisplayLabel());
		return to;
	}
	
	public static User getUser(UserEntity from) {
		User to = new User();
		to.setAddressLine1(from.getAddressLine1());
		to.setAddressLine2(from.getAddressLine2());
		to.setAddressLine3(from.getAddressLine3());
		to.setCity(from.getCity());
		to.setCountry(from.getCountry());
		to.setCreatedOn(from.getCreatedOn());
		to.setLastModifiedOn(from.getLastModifiedOn());
		to.setEmail(from.getEmail());
		to.setFirstName(from.getFirstName());
		to.setLastName(from.getLastName());
		to.setMiddleName(from.getMiddleName());
		to.setMobile(from.getMobile());
		to.setUserId(from.getUserId());
		return to;
	}
	
	public static UserEntity getUserEntity(User from) {
		UserEntity to = new UserEntity();
		to.setAddressLine1(from.getAddressLine1());
		to.setAddressLine2(from.getAddressLine2());
		to.setAddressLine3(from.getAddressLine3());
		to.setCity(from.getCity());
		to.setCountry(from.getCountry());
		to.setCreatedOn(from.getCreatedOn());
		to.setLastModifiedOn(from.getLastModifiedOn());
		to.setEmail(from.getEmail());
		to.setFirstName(from.getFirstName());
		to.setLastName(from.getLastName());
		to.setMiddleName(from.getMiddleName());
		to.setMobile(from.getMobile());
		to.setUserId(from.getUserId());
		to.setPassword(from.getPassword());
		return to;
	}
	
	
	
	
	public static UserEnrollmentEntity getUserEnrollmentEntity(UserEnrollment from) {
		UserEnrollmentEntity to = new UserEnrollmentEntity();
		Role r = new Role();
		r.setName(from.getRoleName());
		to.setRole(getRoleEntity(r));
		UserEnrollmentDataEntity uede = new UserEnrollmentDataEntity();
		DynaUtil.generateData(from.getValues(), from.getRoleName(), uede);
		to.setEnrollmentData(uede);
		return to;
	}

	public static PermissionEntity getPermissionEntity(Permission permission) {
		PermissionEntity to = new PermissionEntity();
		to.setName(permission.getName());
		
		return to;
	}
	
	
}
